﻿using System;
using System.Windows.Forms;
using System.Collections;
using CommonTypes.Client;
using System.Collections.Generic;

namespace PuppetMaster
{
    public partial class CalendarViewer : Form
    {   
        public CalendarViewer(string clientName, ArrayList calendar)
        {
            InitializeComponent();

            labelClientName.Text = "Calendar of Client: " + clientName;

            if (calendar == null)
                return;

            foreach (CalendarSlot s in calendar)
            {
                if (s.AssignedReservation != null)
                    listBoxSlots.Items.Add(s.SlotNumber + " : " + s.SlotState + " To: " + s.AssignedReservation);
                else if (s.TentativelyBookedReservations.Count != 0)
                    listBoxSlots.Items.Add(s.SlotNumber + " : " + s.SlotState + " To: " + GetBooked(s.TentativelyBookedReservations));
                else
                    listBoxSlots.Items.Add(s.SlotNumber + " : " + s.SlotState);
            }
        }

        private void buttonClose_Click(object sender, System.EventArgs e)
        {
            this.Close();
        }

        private void buttonGoto_Click(object sender, EventArgs e)
        {
            listBoxSlots.TopIndex = (int) numericUpDown1.Value-1;
        }

        private string GetBooked(SortedDictionary<long, Reservation> d)
        {
            String ret = "";
            
            foreach (Reservation res in d.Values)
            {
                ret += res;
                ret += "; ";
            }
            return ret;
        }
    }
}
